const mongoose = require('mongoose');
const CampusNotice = require('../models/CampusNotice');
const HotTopic = require('../models/HotTopic');
const Activity = require('../models/Activity');
const MarketItem = require('../models/MarketItem');
require('dotenv').config();

const connectDB = require('./db');

// 示例数据
const notices = [
  {
    tag: '学术',
    title: '2025年春季学术讲座系列开始报名',
    date: '2025-06-11'
  },
  {
    tag: '社团',
    title: '学生社团联合会招新活动即将开始',
    date: '2025-06-10'
  },
  {
    tag: '考试',
    title: '关于2025年上半年英语四六级考试的通知',
    date: '2025-06-09'
  },
  {
    tag: '就业',
    title: '2025届毕业生春季校园招聘会',
    date: '2025-06-08'
  },
  {
    tag: '后勤',
    title: '图书馆新增电子阅览室开放通知',
    date: '2025-06-07'
  }
];

const topics = [
  {
    title: '校园5G全覆盖计划讨论',
    count: 1500,
    content: '关于校园网络升级改造的建议和意见征集',
    tags: ['校园建设', '信息化'],
    date: '2025-06-11'
  },
  {
    title: '新食堂餐品种类投票',
    count: 1200,
    content: '新学期食堂菜品更新征求意见',
    tags: ['餐饮', '生活'],
    date: '2025-06-10'
  },
  {
    title: '图书馆24小时自习室申请',
    count: 1000,
    content: '关于开放图书馆24小时自习区的可行性讨论',
    tags: ['学习', '图书馆'],
    date: '2025-06-09'
  }
];

const activities = [
  {
    title: '2025年校园马拉松',
    description: '春季校园马拉松比赛，欢迎全校师生参与',
    location: '田径场',
    startTime: '2025-06-20 08:00',
    endTime: '2025-06-20 12:00',
    category: 'sports'
  },
  {
    title: '创新创业大赛',
    description: '第十届校园创新创业大赛开始报名',
    location: '大学生活动中心',
    startTime: '2025-07-01 09:00',
    endTime: '2025-07-03 17:00',
    category: 'career'
  }
];

const marketItems = [
  {
    title: '全新iPad Pro',
    description: '2024款iPad Pro，太空灰色，256G，全新未拆封',
    price: '5999',
    category: 'digital',
    condition: 'new',
    images: ['/images/market1.jpg'],
    contact: '13800138000'
  },
  {
    title: '二手自行车',
    description: '捷安特自行车，95新，配件齐全',
    price: '599',
    category: 'transportation',
    condition: 'good',
    images: ['/images/market2.jpg'],
    contact: '13800138001'
  }
];

// 初始化数据
async function initData() {
  try {
    await connectDB();
    
    // 清空原有数据
    await Promise.all([
      CampusNotice.deleteMany({}),
      HotTopic.deleteMany({}),
      Activity.deleteMany({}),
      MarketItem.deleteMany({})
    ]);

    // 插入新数据
    await Promise.all([
      CampusNotice.insertMany(notices),
      HotTopic.insertMany(topics),
      Activity.insertMany(activities),
      MarketItem.insertMany(marketItems)
    ]);

    console.log('✅ 示例数据初始化成功');
    process.exit(0);
  } catch (error) {
    console.error('❌ 数据初始化失败:', error);
    process.exit(1);
  }
}

// 执行初始化
initData();
